Page({
    data: {
        currentIndex: null, //tabIndex
        tabHeight: 0,
        // 底部导航栏 
        tabList: [{
            name: "首页",
            id: 0,
            activateSrc: "../../static/tabs/home_1.png",
            src: "../../static/tabs/home.png",
            isBump: false,
        }, {
            name: "发布",
            id: 1,
            src: "../../static/tabs/333.png",
            isBump: true,
        }, {
            name: "我的",
            id: 2,
            activateSrc: "../../static/tabs/my_1.png",
            src: "../../static/tabs/my.png",
            isBump: false,
        }],
    }, // 获取组件高度
    getTabsHeight() {
        var that = this;
        wx.createSelectorQuery().in(this.selectComponent('#tabs')).select('.tab').boundingClientRect(res1 => {
            if (res1.height) {
                that.setData({
                    tabHeight: res1.height + 60 + "px",
                })
            }
        }).exec();
    },
    onLoad() {
        var that = this;
        wx.login({
            success: (res) => {
                if (res.code) {
                    that.onSilentLogin({
                        jsCode: res.code
                    });
                }
            },
        })
    },
    onReady(){
        wx.showShareMenu({
            menus: ['shareAppMessage', 'shareTimeline'],
            withShareTicket:true
        })
    },
    onShow() {
        this.getTabsHeight();
        if (this.data.currentIndex === 0) {
            this.getCityInfo();
        }
        this.RefreshMy();
    },
    // 刷新my页面数据
    RefreshMy(){
        if (this.data.currentIndex === 2) {
            var myChild = this.selectComponent('#my');
            if (myChild) {
                myChild.msgCompute();
                myChild.getUser();
            }
        }
    },
    getCityInfo() { 
        var homeChild = this.selectComponent('#home');
        if (homeChild) {
            homeChild.getCityHistory();
            homeChild.citySearch('', "hostCity");
            homeChild.getAllCityList();
            // 请求行业类型
            homeChild.industryType(); 
        } else {
            setTimeout(() => {
                this.getCityInfo();
            }, 500)
        }
    },
    // 调用静默登录 
    async onSilentLogin(data) {
        var that = this;
        await getApp().http.silentLogin(data).then(res => {
            getApp().http.updateUserInfo();
            that.setData({
                currentIndex: 0
            });
            setTimeout(() => {
                var homeChild = that.selectComponent('#home');
                homeChild.getCityHistory();
                homeChild.pullDown()
                homeChild.citySearch({
                    cityCode: "",
                    cityName: "hotCitys",
                }, 'myDistrict')
            }, 200)
        })
    },
    // 修改tabIndex
    setTabChanges(e) {
        this.getTabsHeight();
        setTimeout(() => {
            let componentInfo = this.selectComponent('#home');
            console.log(componentInfo?.setPaddingTop());
        }, 80)
        if (Number(e.detail) === 1) {
            wx.navigateTo({
                url: '/pages/releaseinfo/releaseinfo',
            })
        } else {
            this.setData({
                currentIndex: Number(e.detail)
            })
        }
    }
})